﻿using ShiQuan.DataRepository;
using ShiQuan.Helper;
using ShiQuan.IotDevice.Business;
using ShiQuan.IotDevice.Entity;
using ShiQuan.Provider;
using ShiQuan.WebBase;
using ShiQuan.WebControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ShiQuan.IotDevice.Web.Areas.IotDeviceManage.Controllers
{
    /// <summary>
    /// 农残设备安装信息
    /// </summary>
    public class DeviceInstallController : BaseMvcController
    {
        // GET: IotDeviceManage/DeviceInstall
        DeviceInstallBLL service = new DeviceInstallBLL();
        public ActionResult DeviceInstallIndex()
        {
            return View();
        }
        public ActionResult DeviceInstallForm()
        {
            return View();
        }

        #region 获取数据
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagination">分页参数</param>
        /// <param name="queryJson">查询参数</param>
        /// <returns>返回分页列表Json</returns>
        [HttpGet]
        public ActionResult GetPageListJson(Pagination pagination, string queryJson)
        {
            var watch = CommonHelper.TimerStart();
            var data = service.GetPageList(pagination, queryJson);
            var jsonData = new
            {
                rows = data,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };
            return ToJsonResult(jsonData);
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="queryJson">查询参数</param>
        /// <returns>返回列表Json</returns>
        [HttpGet]
        public ActionResult GetListJson(string queryJson)
        {
            var data = service.GetList(queryJson);
            return ToJsonResult(data);
        }
        /// <summary>
        /// 功能列表 
        /// </summary>
        /// <param name="queryJson">关键字</param>
        /// <returns>返回树形Json</returns>
        [HttpGet]
        public ActionResult GetTreeJson(string queryJson)
        {
            var treeList = service.GetTreeList(queryJson);
            return Content(treeList.TreeToJson());
        }
        /// <summary>
        /// 获取实体 
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <returns>返回对象Json</returns>
        [HttpGet]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = service.GetEntity(keyValue);
            return ToJsonResult(data);
        }

        /// <summary>
        /// 获取实体 
        /// </summary>
        /// <param name="customerId">主键值</param>
        /// <returns>返回对象Json</returns>
        [HttpGet]
        public ActionResult GetNewEntity(string customerId,string deviceId)
        {
            var data = service.GetNewEntity(customerId, deviceId);
            return ToJsonResult(data);
        }
        #endregion

        #region 提交数据
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [HandlerAuthorize(PermissionMode.Enforce)]
        [AjaxOnly]
        public ActionResult RemoveForm(string keyValue)
        {
            service.RemoveForm(keyValue);
            return Success("删除成功。");
        }
        /// <summary>
        /// 保存表单（新增、修改）
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        public ActionResult SaveForm(string keyValue, DeviceInstallEntity entity)
        {
            service.SaveForm(keyValue, entity);
            return Success("操作成功。");
        }
        #endregion
    }
}